package com.wei.miaosha.controller;

import com.wei.miaosha.result.Result;
import com.wei.miaosha.service.MiaoshaUserService;
import com.wei.miaosha.util.LogUtils;
import com.wei.miaosha.vo.LoginVo;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * Created by Weizichen on 2018/8/8.
 * desc:登录页面
 */
@Controller
@RequestMapping("/login")
public class LoginController {
    private static org.apache.logging.log4j.Logger logger = LogManager.getLogger("LoginController");

    @Autowired
    MiaoshaUserService miaoshaUserService;

    @RequestMapping("/to_login")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/do_login")
    @ResponseBody
    public Result<String> doLogin(@Valid LoginVo loginVo, HttpServletResponse response) {
        //登录
        String token = miaoshaUserService.login(loginVo, response);
        LogUtils.infoLog(logger, " " + "-" + " " + "-" + " " + "success" + " " + "登录");
        return Result.success(token);
    }
}
